package com.lifo.taobaoshop.service.serviceimpl;

import com.lifo.taobaoshop.bean.model.HfTaobaoShop;
import com.lifo.taobaoshop.dao.HfTaobaoShopMapper;
import com.lifo.taobaoshop.service.HfTaobaoShopManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * Created by Administrator on 2018/5/25 0025.
 */
@Service
@Slf4j
public class HfTaobaoShopManagerServiceImpl implements HfTaobaoShopManagerService{

    @Autowired
    private HfTaobaoShopMapper hfTaobaoShopDao;

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public void saveHfTaobaoShop(HfTaobaoShop hfTaobaoShop) {
        try {
            hfTaobaoShopDao.saveHfTaobaoShop(hfTaobaoShop);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            log.error("保存淘宝店铺失败，店铺名==>{}",hfTaobaoShop.getShopName());
            e.printStackTrace();
        }
    }

    @Override
    public HfTaobaoShop getHfTaobaoShopByShopId(long shopId) {
        HfTaobaoShop hfTaobaoShop = null;
        try {
            hfTaobaoShop = hfTaobaoShopDao.getHfTaobaoShopByShopId(shopId);
        } catch (Exception e) {
            log.error("查询淘宝店信息错误,shopId==>{}",shopId);
            e.printStackTrace();
        }
        return hfTaobaoShop;
    }
}
